/* 
 * File: main.c
 * Author: Testuya Idota and Brian Fehrman
 * Description: Sends commands to the iRobot
 * 				from the Seeduino via USART
 * 				communication. The robot will
 * 				be commanded to drive in a square,
 * 				turn around, and then drive back.
 * Created on (date): 2-5-2013
 */
#include <avr/io.h>
#include <util/delay.h>
#include <inttypes.h>

#include "usart.h"

int main (void)
{
	// call usart initialize
	usart_config ucon;
	ucon.number = 1;
	ucon.baudrate = 57600;
	configure_usart(&ucon);
    
	_delay_ms(1000); //wait for a second

	usart1tx((uint8_t)128); //Start
	
	_delay_ms(1000); //wait for a second
	
	usart1tx((uint8_t)131); //to Safe Mode
	
	_delay_ms(1000);
	

	while(1){
		//clockwise
		int i = 0;
		while(i < 3){
			DriveDist(100,500);
			TurnAngle(-90);
			_delay_ms(6000);
			i++;
		}
		
		DriveDist(100,500);
		
		//return
		Rotate180();
		
		_delay_ms(6000);
		
		//counter-clockwise
		i = 0;
		while(i < 3){
			DriveDist(100,500);
			TurnAngle(90);
			_delay_ms(6000);
			i++;
		}
		
		DriveDist(100,500);
		
		//return
		Rotate180();
		
		_delay_ms(6000);
	}

	return -1;
}
